package com.feel.easycloud.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AuthorizationInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String uri = request.getRequestURI();
        if ("/api/auth/user/login".equals(uri)
           || "/graphic/generate/verificationcode".equals(uri)
           || "/forgetPassword/sendEmail".equals(uri)
        ) {
            return true;
        }

        String authorization = request.getHeader("Authorization");
        if (authorization != null && authorization.startsWith("Bearer ")) {
            return true;
        }
        System.out.println(authorization);
        return false;
    }
}
